cmake_minimum_required(VERSION 2.8)
project(libprotobuf)
set(CMAKE_DEBUG_POSTFIX "D")
find_package(Threads REQUIRED)
if (CMAKE_USE_PTHREADS_INIT)
  add_definitions(-DHAVE_PTHREAD)
endif()

set(libprotobuf_files
  google/protobuf/any.cc
  google/protobuf/any.pb.cc
  google/protobuf/api.pb.cc
  google/protobuf/compiler/importer.cc
  google/protobuf/compiler/parser.cc
  google/protobuf/descriptor.cc
  google/protobuf/descriptor.pb.cc
  google/protobuf/descriptor_database.cc
  google/protobuf/duration.pb.cc
  google/protobuf/dynamic_message.cc
  google/protobuf/empty.pb.cc
  google/protobuf/extension_set_heavy.cc
  google/protobuf/field_mask.pb.cc
  google/protobuf/generated_message_reflection.cc
  google/protobuf/generated_message_table_driven.cc
  google/protobuf/io/gzip_stream.cc
  google/protobuf/io/printer.cc
  google/protobuf/io/strtod.cc
  google/protobuf/io/tokenizer.cc
  google/protobuf/io/zero_copy_stream_impl.cc
  google/protobuf/map_field.cc
  google/protobuf/message.cc
  google/protobuf/reflection_ops.cc
  google/protobuf/service.cc
  google/protobuf/source_context.pb.cc
  google/protobuf/struct.pb.cc
  google/protobuf/stubs/mathlimits.cc
  google/protobuf/stubs/substitute.cc
  google/protobuf/text_format.cc
  google/protobuf/timestamp.pb.cc
  google/protobuf/type.pb.cc
  google/protobuf/unknown_field_set.cc
  google/protobuf/util/delimited_message_util.cc
  google/protobuf/util/field_comparator.cc
  google/protobuf/util/field_mask_util.cc
  google/protobuf/util/internal/datapiece.cc
  google/protobuf/util/internal/default_value_objectwriter.cc
  google/protobuf/util/internal/error_listener.cc
  google/protobuf/util/internal/field_mask_utility.cc
  google/protobuf/util/internal/json_escaping.cc
  google/protobuf/util/internal/json_objectwriter.cc
  google/protobuf/util/internal/json_stream_parser.cc
  google/protobuf/util/internal/object_writer.cc
  google/protobuf/util/internal/proto_writer.cc
  google/protobuf/util/internal/protostream_objectsource.cc
  google/protobuf/util/internal/protostream_objectwriter.cc
  google/protobuf/util/internal/type_info.cc
  google/protobuf/util/internal/type_info_test_helper.cc
  google/protobuf/util/internal/utility.cc
  google/protobuf/util/json_util.cc
  google/protobuf/util/message_differencer.cc
  google/protobuf/util/time_util.cc
  google/protobuf/util/type_resolver_util.cc
  google/protobuf/wire_format.cc
  google/protobuf/wrappers.pb.cc
)

set(libprotobuf_includes
  google/protobuf/any.h
  google/protobuf/any.pb.h
  google/protobuf/api.pb.h
  google/protobuf/compiler/importer.h
  google/protobuf/compiler/parser.h
  google/protobuf/descriptor.h
  google/protobuf/descriptor.pb.h
  google/protobuf/descriptor_database.h
  google/protobuf/duration.pb.h
  google/protobuf/dynamic_message.h
  google/protobuf/empty.pb.h
  google/protobuf/field_mask.pb.h
  google/protobuf/generated_message_reflection.h
  google/protobuf/io/gzip_stream.h
  google/protobuf/io/printer.h
  google/protobuf/io/strtod.h
  google/protobuf/io/tokenizer.h
  google/protobuf/io/zero_copy_stream_impl.h
  google/protobuf/map_field.h
  google/protobuf/message.h
  google/protobuf/reflection_ops.h
  google/protobuf/service.h
  google/protobuf/source_context.pb.h
  google/protobuf/struct.pb.h
  google/protobuf/stubs/mathlimits.h
  google/protobuf/stubs/substitute.h
  google/protobuf/text_format.h
  google/protobuf/timestamp.pb.h
  google/protobuf/type.pb.h
  google/protobuf/unknown_field_set.h
  google/protobuf/util/delimited_message_util.h
  google/protobuf/util/field_comparator.h
  google/protobuf/util/field_mask_util.h
  google/protobuf/util/internal/datapiece.h
  google/protobuf/util/internal/default_value_objectwriter.h
  google/protobuf/util/internal/error_listener.h
  google/protobuf/util/internal/field_mask_utility.h
  google/protobuf/util/internal/json_escaping.h
  google/protobuf/util/internal/json_objectwriter.h
  google/protobuf/util/internal/json_stream_parser.h
  google/protobuf/util/internal/object_writer.h
  google/protobuf/util/internal/proto_writer.h
  google/protobuf/util/internal/protostream_objectsource.h
  google/protobuf/util/internal/protostream_objectwriter.h
  google/protobuf/util/internal/type_info.h
  google/protobuf/util/internal/type_info_test_helper.h
  google/protobuf/util/internal/utility.h
  google/protobuf/util/json_util.h
  google/protobuf/util/message_differencer.h
  google/protobuf/util/time_util.h
  google/protobuf/util/type_resolver_util.h
  google/protobuf/wire_format.h
  google/protobuf/wrappers.pb.h
)

set(libprotobuf_lite_files
  google/protobuf/arena.cc
  google/protobuf/arenastring.cc
  google/protobuf/extension_set.cc
  google/protobuf/generated_message_table_driven_lite.cc
  google/protobuf/generated_message_util.cc
  google/protobuf/implicit_weak_message.cc
  google/protobuf/io/coded_stream.cc
  google/protobuf/io/zero_copy_stream.cc
  google/protobuf/io/zero_copy_stream_impl_lite.cc
  google/protobuf/message_lite.cc
  google/protobuf/repeated_field.cc
  google/protobuf/stubs/bytestream.cc
  google/protobuf/stubs/common.cc
  google/protobuf/stubs/int128.cc
  google/protobuf/stubs/io_win32.cc
  google/protobuf/stubs/status.cc
  google/protobuf/stubs/statusor.cc
  google/protobuf/stubs/stringpiece.cc
  google/protobuf/stubs/stringprintf.cc
  google/protobuf/stubs/structurally_valid.cc
  google/protobuf/stubs/strutil.cc
  google/protobuf/stubs/time.cc
  google/protobuf/wire_format_lite.cc
)

set(libprotobuf_lite_includes
  google/protobuf/arena.h
  google/protobuf/arenastring.h
  google/protobuf/extension_set.h
  google/protobuf/generated_message_util.h
  google/protobuf/implicit_weak_message.h
  google/protobuf/io/coded_stream.h
  google/protobuf/io/zero_copy_stream.h
  google/protobuf/io/zero_copy_stream_impl_lite.h
  google/protobuf/message_lite.h
  google/protobuf/repeated_field.h
  google/protobuf/stubs/bytestream.h
  google/protobuf/stubs/common.h
  google/protobuf/stubs/int128.h
  google/protobuf/stubs/once.h
  google/protobuf/stubs/status.h
  google/protobuf/stubs/statusor.h
  google/protobuf/stubs/stringpiece.h
  google/protobuf/stubs/stringprintf.h
  google/protobuf/stubs/strutil.h
  google/protobuf/stubs/time.h
  google/protobuf/wire_format_lite.h
)

set(libprotoc_files
  google/protobuf/compiler/code_generator.cc
  google/protobuf/compiler/command_line_interface.cc
  google/protobuf/compiler/cpp/cpp_enum.cc
  google/protobuf/compiler/cpp/cpp_enum_field.cc
  google/protobuf/compiler/cpp/cpp_extension.cc
  google/protobuf/compiler/cpp/cpp_field.cc
  google/protobuf/compiler/cpp/cpp_file.cc
  google/protobuf/compiler/cpp/cpp_generator.cc
  google/protobuf/compiler/cpp/cpp_helpers.cc
  google/protobuf/compiler/cpp/cpp_map_field.cc
  google/protobuf/compiler/cpp/cpp_message.cc
  google/protobuf/compiler/cpp/cpp_message_field.cc
  google/protobuf/compiler/cpp/cpp_padding_optimizer.cc
  google/protobuf/compiler/cpp/cpp_primitive_field.cc
  google/protobuf/compiler/cpp/cpp_service.cc
  google/protobuf/compiler/cpp/cpp_string_field.cc
  google/protobuf/compiler/csharp/csharp_doc_comment.cc
  google/protobuf/compiler/csharp/csharp_enum.cc
  google/protobuf/compiler/csharp/csharp_enum_field.cc
  google/protobuf/compiler/csharp/csharp_field_base.cc
  google/protobuf/compiler/csharp/csharp_generator.cc
  google/protobuf/compiler/csharp/csharp_helpers.cc
  google/protobuf/compiler/csharp/csharp_map_field.cc
  google/protobuf/compiler/csharp/csharp_message.cc
  google/protobuf/compiler/csharp/csharp_message_field.cc
  google/protobuf/compiler/csharp/csharp_primitive_field.cc
  google/protobuf/compiler/csharp/csharp_reflection_class.cc
  google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
  google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
  google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
  google/protobuf/compiler/csharp/csharp_source_generator_base.cc
  google/protobuf/compiler/csharp/csharp_wrapper_field.cc
  google/protobuf/compiler/java/java_context.cc
  google/protobuf/compiler/java/java_doc_comment.cc
  google/protobuf/compiler/java/java_enum.cc
  google/protobuf/compiler/java/java_enum_field.cc
  google/protobuf/compiler/java/java_enum_field_lite.cc
  google/protobuf/compiler/java/java_enum_lite.cc
  google/protobuf/compiler/java/java_extension.cc
  google/protobuf/compiler/java/java_extension_lite.cc
  google/protobuf/compiler/java/java_field.cc
  google/protobuf/compiler/java/java_file.cc
  google/protobuf/compiler/java/java_generator.cc
  google/protobuf/compiler/java/java_generator_factory.cc
  google/protobuf/compiler/java/java_helpers.cc
  google/protobuf/compiler/java/java_lazy_message_field.cc
  google/protobuf/compiler/java/java_lazy_message_field_lite.cc
  google/protobuf/compiler/java/java_map_field.cc
  google/protobuf/compiler/java/java_map_field_lite.cc
  google/protobuf/compiler/java/java_message.cc
  google/protobuf/compiler/java/java_message_builder.cc
  google/protobuf/compiler/java/java_message_builder_lite.cc
  google/protobuf/compiler/java/java_message_field.cc
  google/protobuf/compiler/java/java_message_field_lite.cc
  google/protobuf/compiler/java/java_message_lite.cc
  google/protobuf/compiler/java/java_name_resolver.cc
  google/protobuf/compiler/java/java_primitive_field.cc
  google/protobuf/compiler/java/java_primitive_field_lite.cc
  google/protobuf/compiler/java/java_service.cc
  google/protobuf/compiler/java/java_shared_code_generator.cc
  google/protobuf/compiler/java/java_string_field.cc
  google/protobuf/compiler/java/java_string_field_lite.cc
  google/protobuf/compiler/js/js_generator.cc
  google/protobuf/compiler/js/well_known_types_embed.cc
  google/protobuf/compiler/objectivec/objectivec_enum.cc
  google/protobuf/compiler/objectivec/objectivec_enum_field.cc
  google/protobuf/compiler/objectivec/objectivec_extension.cc
  google/protobuf/compiler/objectivec/objectivec_field.cc
  google/protobuf/compiler/objectivec/objectivec_file.cc
  google/protobuf/compiler/objectivec/objectivec_generator.cc
  google/protobuf/compiler/objectivec/objectivec_helpers.cc
  google/protobuf/compiler/objectivec/objectivec_map_field.cc
  google/protobuf/compiler/objectivec/objectivec_message.cc
  google/protobuf/compiler/objectivec/objectivec_message_field.cc
  google/protobuf/compiler/objectivec/objectivec_oneof.cc
  google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
  google/protobuf/compiler/php/php_generator.cc
  google/protobuf/compiler/plugin.cc
  google/protobuf/compiler/plugin.pb.cc
  google/protobuf/compiler/python/python_generator.cc
  google/protobuf/compiler/ruby/ruby_generator.cc
  google/protobuf/compiler/subprocess.cc
  google/protobuf/compiler/zip_writer.cc
)

set(libprotoc_headers
  google/protobuf/compiler/cpp/cpp_enum.h
  google/protobuf/compiler/cpp/cpp_enum_field.h
  google/protobuf/compiler/cpp/cpp_extension.h
  google/protobuf/compiler/cpp/cpp_field.h
  google/protobuf/compiler/cpp/cpp_file.h
  google/protobuf/compiler/cpp/cpp_helpers.h
  google/protobuf/compiler/cpp/cpp_map_field.h
  google/protobuf/compiler/cpp/cpp_message.h
  google/protobuf/compiler/cpp/cpp_message_field.h
  google/protobuf/compiler/cpp/cpp_message_layout_helper.h
  google/protobuf/compiler/cpp/cpp_options.h
  google/protobuf/compiler/cpp/cpp_padding_optimizer.h
  google/protobuf/compiler/cpp/cpp_primitive_field.h
  google/protobuf/compiler/cpp/cpp_service.h
  google/protobuf/compiler/cpp/cpp_string_field.h
  google/protobuf/compiler/csharp/csharp_doc_comment.h
  google/protobuf/compiler/csharp/csharp_enum.h
  google/protobuf/compiler/csharp/csharp_enum_field.h
  google/protobuf/compiler/csharp/csharp_field_base.h
  google/protobuf/compiler/csharp/csharp_helpers.h
  google/protobuf/compiler/csharp/csharp_map_field.h
  google/protobuf/compiler/csharp/csharp_message.h
  google/protobuf/compiler/csharp/csharp_message_field.h
  google/protobuf/compiler/csharp/csharp_options.h
  google/protobuf/compiler/csharp/csharp_primitive_field.h
  google/protobuf/compiler/csharp/csharp_reflection_class.h
  google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
  google/protobuf/compiler/csharp/csharp_repeated_message_field.h
  google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
  google/protobuf/compiler/csharp/csharp_source_generator_base.h
  google/protobuf/compiler/csharp/csharp_wrapper_field.h
  google/protobuf/compiler/java/java_context.h
  google/protobuf/compiler/java/java_doc_comment.h
  google/protobuf/compiler/java/java_enum.h
  google/protobuf/compiler/java/java_enum_field.h
  google/protobuf/compiler/java/java_enum_field_lite.h
  google/protobuf/compiler/java/java_enum_lite.h
  google/protobuf/compiler/java/java_extension.h
  google/protobuf/compiler/java/java_extension_lite.h
  google/protobuf/compiler/java/java_field.h
  google/protobuf/compiler/java/java_file.h
  google/protobuf/compiler/java/java_generator_factory.h
  google/protobuf/compiler/java/java_helpers.h
  google/protobuf/compiler/java/java_lazy_message_field.h
  google/protobuf/compiler/java/java_lazy_message_field_lite.h
  google/protobuf/compiler/java/java_map_field.h
  google/protobuf/compiler/java/java_map_field_lite.h
  google/protobuf/compiler/java/java_message.h
  google/protobuf/compiler/java/java_message_builder.h
  google/protobuf/compiler/java/java_message_builder_lite.h
  google/protobuf/compiler/java/java_message_field.h
  google/protobuf/compiler/java/java_message_field_lite.h
  google/protobuf/compiler/java/java_message_lite.h
  google/protobuf/compiler/java/java_name_resolver.h
  google/protobuf/compiler/java/java_options.h
  google/protobuf/compiler/java/java_primitive_field.h
  google/protobuf/compiler/java/java_primitive_field_lite.h
  google/protobuf/compiler/java/java_service.h
  google/protobuf/compiler/java/java_shared_code_generator.h
  google/protobuf/compiler/java/java_string_field.h
  google/protobuf/compiler/java/java_string_field_lite.h
  google/protobuf/compiler/objectivec/objectivec_enum.h
  google/protobuf/compiler/objectivec/objectivec_enum_field.h
  google/protobuf/compiler/objectivec/objectivec_extension.h
  google/protobuf/compiler/objectivec/objectivec_field.h
  google/protobuf/compiler/objectivec/objectivec_file.h
  google/protobuf/compiler/objectivec/objectivec_helpers.h
  google/protobuf/compiler/objectivec/objectivec_map_field.h
  google/protobuf/compiler/objectivec/objectivec_message.h
  google/protobuf/compiler/objectivec/objectivec_message_field.h
  google/protobuf/compiler/objectivec/objectivec_oneof.h
  google/protobuf/compiler/objectivec/objectivec_primitive_field.h
  google/protobuf/compiler/subprocess.h
  google/protobuf/compiler/zip_writer.h
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIRS})

add_library(libprotoc SHARED ${libprotoc_files} ${libprotoc_headers})
add_library(${PROJECT_NAME}-lite SHARED ${libprotobuf_lite_files} ${libprotobuf_lite_includes})
add_library(${PROJECT_NAME} SHARED ${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes})
add_executable(protoc google/protobuf/compiler/main.cc)
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD /bigobj)
target_compile_definitions(libprotoc PUBLIC PROTOBUF_USE_DLLS PRIVATE LIBPROTOC_EXPORTS)
target_compile_definitions(${PROJECT_NAME}-lite PUBLIC PROTOBUF_USE_DLLS PRIVATE LIBPROTOBUF_EXPORTS)
target_compile_definitions(${PROJECT_NAME} PUBLIC PROTOBUF_USE_DLLS PRIVATE LIBPROTOBUF_EXPORTS)

target_link_libraries(protoc ${PROJECT_NAME} libprotoc)
target_link_libraries(${PROJECT_NAME}-lite ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(libprotoc ${PROJECT_NAME})

add_library(protobuf::libprotoc ALIAS libprotoc)
add_library(protobuf::libprotobuf-lite ALIAS libprotobuf-lite)
add_library(protobuf::libprotobuf ALIAS libprotobuf)

install(DIRECTORY google DESTINATION include FILES_MATCHING PATTERN "*.h"
  PATTERN "google/protobuf/descriptor.proto"
  PATTERN "google/protobuf/any.proto"
  PATTERN "google/protobuf/api.proto"
  PATTERN "google/protobuf/duration.proto"
  PATTERN "google/protobuf/empty.proto"
  PATTERN "google/protobuf/field_mask.proto"
  PATTERN "google/protobuf/source_context.proto"
  PATTERN "google/protobuf/struct.proto"
  PATTERN "google/protobuf/timestamp.proto"
  PATTERN "google/protobuf/type.proto"
  PATTERN "google/protobuf/wrappers.proto"
  PATTERN "google/protobuf/compiler/plugin.proto")
install(TARGETS protoc RUNTIME DESTINATION bin)

install(TARGETS libprotoc EXPORT libprotoc-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
install(TARGETS ${PROJECT_NAME}-lite EXPORT ${PROJECT_NAME}-lite-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
install(EXPORT libprotoc-targets DESTINATION lib/cmake FILE libprotoc-config.cmake)
install(EXPORT ${PROJECT_NAME}-lite-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}-lite-config.cmake)
install(EXPORT ${PROJECT_NAME}-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}-config.cmake)

if(BUILD_STATIC)
  add_library(${PROJECT_NAME}S STATIC ${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes})
  add_library(${PROJECT_NAME}-liteS STATIC ${libprotobuf_lite_files} ${libprotobuf_lite_includes})
  add_library(libprotocS STATIC ${libprotoc_files} ${libprotoc_headers})
  install(TARGETS ${PROJECT_NAME}S EXPORT ${PROJECT_NAME}S-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
  install(TARGETS ${PROJECT_NAME}-liteS EXPORT ${PROJECT_NAME}-liteS-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
  install(TARGETS libprotocS EXPORT libprotocS-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
  install(EXPORT ${PROJECT_NAME}S-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}S-config.cmake)
  install(EXPORT ${PROJECT_NAME}-liteS-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}-liteS-config.cmake)
  install(EXPORT libprotocS-targets DESTINATION lib/cmake FILE libprotocS-config.cmake)
endif()
